﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;

namespace DevTools.ClassStuffGenerator.Controls
{
    public static class GridExtension
    {
        public static void LoadDefaultSetting(this GridControl grid)
        {
            GridView view = grid.MainView as GridView;

            if (view == null)
                return;

            grid.ShowOnlyPredefinedDetails = true;

            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowFooter = true;
            view.OptionsBehavior.Editable = false;
            view.OptionsSelection.EnableAppearanceFocusedCell = false;
            view.OptionsView.ShowAutoFilterRow = true; 
            view.OptionsView.ShowFilterPanelMode = ShowFilterPanelMode.Never;
            view.OptionsView.ShowFooter = false;
            view.OptionsSelection.MultiSelect = false;
            view.OptionsPrint.AutoWidth = true;
            view.OptionsView.EnableAppearanceEvenRow = true;
            view.BestFitColumns();

            view.IndicatorWidth = 40;
            view.CustomDrawRowIndicator += (sender, e) =>
            {
                if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                {
                    e.Info.ImageIndex = -1;
                    e.Info.DisplayText = (e.RowHandle + 1).ToString("N0");
                }
            };
        }
    }
}
